package com.kaifamiao.nio;

import java.nio.ByteBuffer;

public class RewindBufferTest {

    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocateDirect(1024);
        System.out.println( buffer );
        buffer.putChar('小');
        buffer.putChar('芳');
        buffer.putInt(18);
        buffer.put((byte)0);
        System.out.println( buffer );

        buffer.flip();
        System.out.println( buffer );

        System.out.println( buffer.getChar() + "" + buffer.getChar() );
        System.out.println( buffer );

        // "重绕缓冲区"
        buffer.rewind(); // position = 0 ; mark = -1 ;

        System.out.println( buffer );
    }
}
